/*
Prelim 2020 ANES exploration. Look at climate question, various science misinfo and overconfidence qs
Test for M/F gaps and sexism gaps. */

* Update the path below to your local copy of the 2020 ANES Time Series data (.dta format)
* Available from: https://electionstudies.org/data-center/2020-time-series-study/
use "anes_timeseries_2020_stata_20220210.dta"
set more off

/* Prelim vars of interest:

Partisanship, 7 and 3 point scales
Ideology
Racial resentment
Sexism
Education
Race
Sex
Income */

// Party ID
gen partyid3=.
replace partyid3=1 if V201228==1
replace partyid3=2 if V201228==2
replace partyid3=1 if V201230==3
replace partyid3=2 if V201230==1
replace partyid3=3 if V201230==2
label define partyid3 1 "Democratic" 2 "Republican" 3 "Independent", replace
label values partyid3 partyid3

gen pid3=.
replace pid3=1 if partyid3==1
replace pid3=2 if partyid3==3
replace pid3=3 if partyid3==2
label define pid3 1 "Dem" 2 "Ind/DK" 3 "Rep", replace
label values pid3 pid3

tab V201228 partyid3
tab V201230 partyid3

// Race
tab V201549x
gen race=V201549x
recode race(-9=.r) (-8=.d)
label define race 1 "White" 2 "Black" 3 "Hispanic" 4 "Asian/AAPI" 5 "Native American" 6 "Multiple/non-Hispanic"
label values race race

// Sex
gen male=.
replace male=1 if V201600==1
replace male=0 if V201600==2
label define male 0 "Female" 1 "Male" 
label values male male

// Education
tab V201510, m 
gen educlevel=.
label define educ 1 "High school or less" 2 "Some college but no degree" 3 "Associates degree" 4 "Bachelors degree" 5 "Grad or higher"
replace educ=1 if V201510==1
replace educ=1 if V201510==2
replace educ=2 if V201510==3
replace educ=3 if V201510==4
replace educ=3 if V201510==5
replace educ=4 if V201510==6
replace educ=5 if V201510==7
replace educ=5 if V201510==8
label values educ educ
tab educlevel V201510, m
tab educlevel, gen(educ)

// 4 item racial resentment
// V202300: favors, 1 most racist response - need to reverse
// V202301: generations - 5 most racist response
// V202302: deserve - 5 most racist response
// V202303: tryhard - 1 most racist - need to reverse

gen favors=.
replace favors=1 if V202300==5
replace favors=2 if V202300==4
replace favors=3 if V202300==3
replace favors=4 if V202300==2
replace favors=5 if V202300==1

gen generations=.
replace generations=1 if V202301==1
replace generations=2 if V202301==2
replace generations=3 if V202301==3
replace generations=4 if V202301==4
replace generations=5 if V202301==5

gen deserve=.
replace deserve=1 if V202302==1
replace deserve=2 if V202302==2
replace deserve=3 if V202302==3
replace deserve=4 if V202302==4
replace deserve=5 if V202302==5

gen tryhard=.
replace tryhard=1 if V202303==5
replace tryhard=2 if V202303==4
replace tryhard=3 if V202303==3
replace tryhard=4 if V202303==2
replace tryhard=5 if V202303==1

factor favors generations deserve tryhard

gen resentment=(favors+generations+deserve+tryhard)/4

// 2 item hostile sexism
// V201639: innocent remarks, 1 most sexist response - need to reverse
// V201640: gain control - 1 most sexist - need to reverse

gen innocent=.
replace innocent=1 if V201639==5
replace innocent=2 if V201639==4
replace innocent=3 if V201639==3
replace innocent=4 if V201639==2
replace innocent=5 if V201639==1

gen control=.
replace control=1 if V201640==5
replace control=2 if V201640==4
replace control=3 if V201640==3
replace control=4 if V201640==2
replace control=5 if V201640==1

factor innocent control

gen hostilesexism=(innocent+control)/2

// climate and science questions

// favor/oppose requiring vaccines
tab V202331x
// how much is climate change affecting weather trends
tab V202332
// how important is issue of climate change
tab V202333
// favor/oppose regulation on GHGs
tab V202334

////////////

// do vaccines cause autism
tab V202553
// overconfidence about vaccines and autism
tab V202554
// have world temps risen in last century?
tab V202555
// overconfidence about global temps increasing
tab V202556
// coronavirus misinfo
// intentionally developed in a lab? (conspiracy theory)
tab V202557
// confidence
tab V202558
// HCQ effective treatment
tab V202559
// confidence
tab V202560


//////////////

gen ruralresidency=.
replace ruralresidency=1 if V202355==1
replace ruralresidency=1 if V202355==2
replace ruralresidency=0 if V202355==3
replace ruralresidency=0 if V202355==4

label define ruralresidency 0 "Suburb/city" 1 "Lives in rural/small town", replace
label values ruralresidency ruralresidency

tab V202355 ruralresidency, m


gen ruralidentity=.
replace ruralidentity=1 if V202356==3 
replace ruralidentity=1 if V202356==4
replace ruralidentity=0 if V202356==2
replace ruralidentity=0 if V202356==1

label define ruralidentity 0 "Suburb/city person" 1 "Rural/small town/country person", replace
label values ruralidentity ruralidentity 

tab V202356 ruralidentity, m

////////////

** Environment vs. economy tradeoff Q

gen econvsenv=.
replace econvsenv=1 if V201262==7
replace econvsenv=2 if V201262==6
replace econvsenv=3 if V201262==5
replace econvsenv=4 if V201262==4
replace econvsenv=5 if V201262==3
replace econvsenv=6 if V201262==2
replace econvsenv=7 if V201262==1

label define econvsenv 1 "Too much of a burden on business" 7 "Tougher regs on business needed", replace
label values econvsenv econvsenv 

tab econvsenv V201262

** Climate impact on weather

gen climweather=.
replace climweather=V202332 if V202332>0
label define climweather 1 "Not at all" 2 "A little" 3 "A moderate amount" 4 "A lot" 5 "A great deal"
label values climweather climweather

** Personal importance of climate change

gen climimportance=.
replace climimportance=V202333 if V202333>0
label define climimportance 1 "Not important" 2 "A little" 3 "Moderately important" 4 "Very important" 5 "Extremely important"
label values climimportance climimportance

** Govt regulation on businesses for GHGs

gen ghgregulation=.
label define ghgregulation 1 "Oppose - a great deal" 2 "Oppose - moderately" 3 "Oppose - a little" 4 "Neither favor nor oppose" ///
5 "Favor - a little" 6 "Favor - moderately" 7 "Favor - a great deal", replace

replace ghgregulation=1 if V202334==2 & V202335==1
replace ghgregulation=2 if V202334==2 & V202335==2 
replace ghgregulation=3 if V202334==2 & V202335==3 
replace ghgregulation=4 if V202334==3
replace ghgregulation=5 if V202334==1 & V202335==3
replace ghgregulation=6 if V202334==1 & V202335==2
replace ghgregulation=7 if V202334==1 & V202335==1
label values ghgregulation ghgregulation 

** Have temps risen

gen tempsrisen=.
replace tempsrisen=0 if V202555==2
replace tempsrisen=1 if V202555==1

label define tempsrisen 0 "Temps have not risen" 1 "Temps have risen"
label values temps temps

** age
gen age=V201507x
tab age, m
recode age(-9=.r)

gen agedem=.
label define agedem 1 "18-30" 2 "31-40" 3 "41-50" 4 "51-64" 5 "65+"
replace agedem=1 if age>17 & age<31 & !missing(age)
replace agedem=2 if age>30 & age<41 & !missing(age)
replace agedem=3 if age>40 & age<51 & !missing(age)
replace agedem=4 if age>50 & age<65 & !missing(age) 
replace agedem=5 if age>64 & !missing(age)

label values agedem agedem
tab age agedem, m

** trust in experts
gen trustexperts=.
replace trustexperts=V202308x if V202308x>0
label define trustexperts 1 "Trust ordinary people much more" 2 "Trust ordinary somewhat more" 3 "Trust both the same" 4 "Trust experts somewhat more" 5 "Trust experts much more"
label values trustexperts trustexperts

tab trustexperts V202308x, m

gen trustgovt=.
label define trustgovt 1 "Never" 2 "Some of the time" 3 "About half the time" 4 "Most of the time" 5 "Always"
replace trustgovt=1 if V201233==5
replace trustgovt=2 if V201233==4
replace trustgovt=3 if V201233==3
replace trustgovt=4 if V201233==2
replace trustgovt=5 if V201233==1
label values trustgovt trustgovt

label variable econvsenv "Econ vs. environment tradeoff"
label variable climweather "Climate change impact on severe weather"
label variable climimportance "Climate change personal importance"
label variable ghgregulation "GHG regulations on polluters"
label variable tempsrisen "Evidence that global temps have increased"

gen collegedeg=.
replace collegedeg=0 if educlevel<=3 & !missing(educlevel)
replace collegedeg=1 if educlevel>=4 & !missing(educlevel)

gen ideology=.
replace ideology=1 if V201200==1
replace ideology=2 if V201200==2
replace ideology=3 if V201200==3
replace ideology=4 if V201200==4
replace ideology=5 if V201200==5
replace ideology=6 if V201200==6
replace ideology=7 if V201200==7
label define ideology 1 "V liberal" 2 "Liberal" 3 "Somewhat liberal" 4 "Moderate" 5 "Somewhat conservative" 6 "Conservative" 7 "Very conservative"
label values ideology ideology

/////////////////////////////////////
// post-election wt = V200010b

reg temps b3.partyid3 male i.agedem college [pweight=V200010b] 

set scheme plottig
reg temps b2.pid3 male i.agedem college [pweight=V200010b] 
eststo All
margins, at(pid=(1,2,3)) 
mplotoffset, recast(scatter) offset(0.15) title("ANES 2020: Agreement that global temperatures are increasing") ///
xtitle("Partisanship") ytitle("Predicted probabilities") legend(ring(1) pos(6) row(1)) 

reg temps b3.partyid3 male i.agedem college [pweight=V200010b] 

set scheme plottig
reg temps b2.pid3 male i.agedem college [pweight=V200010b] 
eststo All
margins, at(pid=(1,2,3)) 
mplotoffset, recast(scatter) offset(0.15) title("ANES 2020: Agreement that global temperatures are increasing") ///
xtitle("Partisanship") ytitle("Predicted probabilities") legend(ring(1) pos(6) row(1)) 


* cd to output directory (update as needed)

eststo clear
set scheme plottig
logit temps b2.pid3 male i.agedem college [pweight=V200010b] 
eststo All
margins, at(pid=(1,2,3)) 
mplotoffset, recast(scatter) offset(0.15) title("Global temperatures increasing") ///
ylabel(0 "0" .10 "10%" .20 "20%" .30 "30%" .40 "40%" .50 "50%" .60 "60%" .70 "70%" .80 "80%" .90 "90%" 1 "100%") ///
xtitle("Partisanship") ytitle("Predicted probabilities") legend(ring(1) pos(6) row(1)) 
graph save ANES, replace

graph combine "ANES" "Pew", col(2)
//

mean temps [pweight=V200010b]
mean temps [pweight=V200010b], over(pid3)